package com.prs.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
 * 
 * <p>Title: MD5Util</p>
 * <p>Description: 加密工具类</p>
 * <p>Copyright: Copyright 2011</p>
 * @author flybonew@163.com
 * @date 2011-12-1
 * @since 1.0
 */
public class MD5Util {

	private MD5Util() {

	}

	/**
	 * 加密字符串
	 * 
	 * @param password
	 * @return
	 */
	public static String getMd5Str(String password) {
		StringBuffer buf = new StringBuffer();
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(password.getBytes());
			byte b[] = md.digest();
			int i;
			for (int offset = 0; offset < b.length; offset++) {
				i = b[offset];
				if (i < 0)
					i += 256;
				if (i < 16)
					buf.append("0");
				buf.append(Integer.toHexString(i));
			}
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return buf.toString();
	}
}
